#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

int main() {
    cv::Mat srcImage = cv::imread("/Users/chris/Documents/python-learning-team/杨子萱/example_opencv3_cpp/image/test.jpg");
    if (!srcImage.data) return 2;
    cv::Mat resultImage(srcImage.size(), srcImage.type());

    cv::Mat xMapImage(srcImage.size(), CV_32FC1);
    cv::Mat yMapImage(srcImage.size(), CV_32FC1);

    int rows = srcImage.rows;
    int cols = srcImage.cols;

    for (int j = 0; j < rows; j++) {
        for (int i = 0; i < cols; i++) {
            xMapImage.at<float>(j, i) = cols - i;
            yMapImage.at<float>(j, i) = rows - j;
        }
    }

    cv::remap(srcImage, resultImage, xMapImage, yMapImage,
              cv::INTER_LINEAR, cv::BORDER_CONSTANT,
              cv::Scalar(0, 0, 0));

    cv::imshow("srcImage", srcImage);
    cv::imshow("resultImage", resultImage);
    cv::waitKey(0);
    return 0;

}